package com.example.s16_springsecurity.controller;

import com.example.s16_springsecurity.service.MethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// @RestController = @Controller + @ResponseBody
// 表示控制器中方法返回的就是要输出的内容,不是视图名

@RestController
public class HelloController {

    @RequestMapping("/")
    public String hello()
    {
        return "Hello";
    }

    @RequestMapping("/admin/hello")
    public String adminHello()
    {
        return "admin hello";
    }

    @RequestMapping("/user/hello")   // ADMIN USER
    public String userHello()
    {
        return "user hello";
    }

    @RequestMapping("/db/hello")
    public String dbHello()
    {
        return "deb hello";
    }



    @Autowired
    MethodService methodService;

    // @GetMapping  = @RequestMapping(method = HttpMethod.GET)
    @GetMapping("/hello1")
    public String hello1() {
        String user = methodService.user();
        return user;
    }

    @GetMapping("/hello2")
    public String hello2() {
        String admin = methodService.admin();
        return admin;
    }

    @GetMapping("/hello3")
    public String hello3() {
        String dba = methodService.dba();
        return dba;
    }

}

// 加入框架后，已起作用

// 用户名: user
// 密码: 0011adc9-9465-4df7-9771-e07f3a85f70a


//    Using generated security password: 0011adc9-9465-4df7-9771-e07f3a85f70a
//    This generated password is for development use only. Your security configuration must be updated before running your application in production.
